import {createStore} from 'vuex'
import request from '../utils/request.js'
const store = createStore({
	state:{
		token: uni.getStorageSync('token'),
		// token: 'YTg3NzkyMzRk77yMOTYyNjk4MDU0OTk0MjUw77yMYTg3NznvvIwxOTQ3MQ==',
		platform:'',////用户手机类型1苹果 2安卓或者其他平台
		userInfo:'',
		extra_params:'',//渠道链接携带的参数
		openVip: false,
		showUpdate: false,
		percentage: 0
	},
	getters: {
		extra(state) {
			return state.extra_params
		},
		token(state) {
			return state.token
		},
		platform(state) {
			return state.platform
		},
		userInfo(state) {
			return state.userInfo
		}
	},
	mutations: {
		setExtra(state,extra) {
			state.extra_params = extra
		},
		setToken(state,token) {
			state.token = token
			uni.setStorageSync('token',token)
		},
		setPlatform(state,platform) {
			state.platform = platform
		},
		setUserInfo(state,userInfo) {
			state.userInfo = userInfo
		}
	},
	actions: {
		getUserInfo({commit,state}) {
			return new Promise((resolve,reject) => {
				request({
					url:'/api/v1/miletus/user/vip',
					method:'get'
				}).then(res => {
					commit('setUserInfo',res)
					resolve(res)
				}).catch(err => {
					reject(err)
				})
			})
		}
	}
}) 
export default store